app.filter('state', [function() {
	return function(state) {
		var str = '';
		angular.forEach(statesArrs2, function(v, k) {
			if(v.state.split(',').indexOf(state) != -1) {
				return str = v.name;
			}
		});
		return str;
	};
}]);

app.filter('to_trusted', [
    '$sce',
    function($sce) {
        return function(content) {
            return $sce.trustAsHtml(content);
        };
    }
]);

app.filter('to_url', [
    function() {
    	var pdf_img = './components/mine/orders/orderdetail/imgs/pdf.png';
    	var cad_img = './components/mine/orders/orderdetail/imgs/cad.png';
        return function(url) {
        	var split_url = url.slice(-3);
	        if(split_url == 'pdf') {
	            return pdf_img;
	        }
	        if(split_url == 'dwg') {
	        	return cad_img;
	        }
            return url;
        };
    }
]);

app.filter('moneyint', [function() {
	return function(money, bool) {
		money = parseFloat(money);
		if(!money) {
			money = 0;
		}
		if(bool) {
			money /= 100;
		}
		return parseFloat(money).toFixed(2);
	};
}]);

app.filter('paystatus', [function() {
	return function(status) {
		switch(status) {
			case 'new':
				return "等待付款";
			case 'pending':
				return "付款中";
			case 'cancel':
				return "取消";
			case 'complete':
				return "完成";
			case 'locked':
				return "冻结";
			default:
				return "等待付款";
		}
	};
}]);

app.filter('raty', [function() {
	return function(raty) {
		if(raty == 0) {
			return '100%';
		} else {
			if(raty > 5) {
				raty = 5;
			}
			return parseInt(raty / 5 * 100) + '%';
		}

	};
}]);

app.filter('paytype', [function() {
	return function(type) {
		switch(type) {
			case 'alipay_pc_direct':
				return '支付宝';
			case 'alipay_wap':
				return '支付宝';
			case 'wx':
				return '微信';
			case 'wx_pub':
				return '微信';
			case 'local':
				return '订单费用';
				// return '站内交易';
			case 'profit':
				return '昨日收益';
		};
	};
}]);

app.filter('percent', [function() {
	return function(num) {
		if(!num) { return }
		num *= 100;
		return num + '%';
	};
}]);

app.filter('usertype', ['$rootScope', function($rootScope) {
	return function(type) {
		// console.log('type', type)
		var str = '';
		angular.forEach($rootScope.roles, function(v, k) {
			if(v.rules == type) {
				str =  v.name;
			}
		});
		return str;
	};
}]);